// pages/list/list.js
var app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    arr: [],
    pageIndex: 1,
    pageSize: 10,
    hasData: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      windowHeight: app.globalData.windowHeight
    });
    this.ajax();
  },
  goPush:function(e){
    wx.navigateTo({
      url: '../anchor/anchor?id=' + e.currentTarget.id +'&push_flow_url='+encodeURI(e.currentTarget.dataset.url),
    })
  },
  ajax: function () {
    var that = this;
    //wx.showLoading();
    wx.request({
      url: 'https://wx.sencegroup.com/xingchen/api/zbds/shop/getMyLiveList',
      data: {
        token: app.globalData.token,
        pageSize: that.data.pageSize,
        pageIndex: that.data.pageIndex
      },
      method: "GET",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"  //post
      },
      complete: function (res) {
        //wx.hideLoading();
      },
      success: function (res) {
        console.log(res);
        if (res.data.code == 0) {
          var arrBox;
          if (that.data.pageIndex == 1) {
            arrBox = res.data.data.rows;
          } else {
            arrBox = that.data.arr.concat(res.data.data.rows)
          };
          if (that.data.pageSize * that.data.pageIndex < res.data.data.recordCount) {
            var num = that.data.pageIndex + 1;
            that.setData({
              arr: arrBox,
              hasData: true,
              pageIndex: num
            });
          } else {
            that.setData({
              arr: arrBox,
              hasData: false
            });
          }
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: "none"
          })
        }
      }
    })
  },
  /**
  * 页面相关事件处理函数--监听用户下拉动作
  */
  onPullDownRefresh: function () {
    this.setData({
      pageIndex: 1,
      hasData: true
    });
    this.ajax();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.hasData) {
      this.ajax();
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})